﻿/*
 * @author: wizardc
 */

using System;
using UnityEditor;
using UnityEngine;
using Object = UnityEngine.Object;

namespace Demo.WorldMap
{
    /// <summary>
    /// 资源加载工具类
    /// 方便后面直接对接项目实际使用的资源框架
    /// </summary>
    public static class WorldMapAssetUtil
    {
        /// <summary>
        /// 通过文件名获取对应的文件路径
        /// </summary>
        public static string GetAssetPath(string fileName)
        {
            // 简单场景
            return "Assets/Demo/WorldMap/SimpleRes/ResStream/SceneStaticTransform.bytes";
        }
        
        /// <summary>
        /// 加载资源，内部引用加 1
        /// </summary>
        public static void LoadObject(string fileName, Action<string, UnityEngine.Object> callback, bool isAsync = true)
        {
#if UNITY_EDITOR
            // 简单场景
            var dir = "Assets/Demo/WorldMap/SimpleRes";

            var guids = AssetDatabase.FindAssets(fileName, new string[] {dir});
            if (guids.Length > 0)
            {
                var obj = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(guids[0]), typeof(Object));
                callback(fileName, obj);
            }
            else
            {
                Debug.LogError("加载资源错误：" + fileName);
            }
#endif
        }

        /// <summary>
        /// 释放资源，内部引用减 1
        /// </summary>
        public static bool ReleaseObject(string fileName)
        {
            return true;
        }
    }
}
